package com.cskaoyan.wordmemorize.controller.admin;


import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocCategoryDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.VocCategoryCommand;
import com.cskaoyan.wordmemorize.service.VocCategoryService;
import jakarta.annotation.Resource;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.web.bind.annotation.*;

@RestController
public class VocCategoryController {

    @Resource
    VocCategoryService vocCategoryService;

    //分页查询书籍类目
    @GetMapping("admin/voc/category/list")
    public Result<PageDTO<VocCategoryDTO>> list(PageRequest pageRequest){
        PageDTO<VocCategoryDTO> page = vocCategoryService.getBookCategories(pageRequest);
        return Result.ok(page);
    }

    //获取指定的书籍类目
    @GetMapping("admin/voc/category")
    public VocCategoryDTO get(Long categoryId){
        VocCategoryDTO bookCategory = vocCategoryService.getBookCategory(categoryId);
        return bookCategory;
    }

    //添加书籍类目
    @OperateLog(dateType = "书籍",operateType = 1)
    @PostMapping("admin/voc/category")
    public Result<String> add(@RequestBody VocCategoryCommand vocCategoryCommand){
        Long l = vocCategoryService.addBookCategory(vocCategoryCommand);
        if(l > 0){
            return Result.ok();
        }else{
            return Result.fail();
        }
    }


    //修改书籍类目
    @OperateLog(dateType = "书籍",operateType = 4)
    @PutMapping("admin/voc/category")
    public Result<String> update(@RequestBody VocCategoryCommand vocCategoryCommand){
        vocCategoryService.updateBookCategory(vocCategoryCommand);
        return Result.ok();
    }

    //删除指定书籍类目
    @OperateLog(dateType = "书籍",operateType = 2)
    @DeleteMapping("admin/voc/category/{categoryId}")
    public Result delete(@PathVariable("categoryId") Long categoryId){
        vocCategoryService.deleteBookCategory(categoryId);
        return Result.ok();
    }

    //批量删除书籍类目
    // @OperateLog(dateType = "书籍",operateType = 3)
    @DeleteMapping("admin/voc/categories")
    public Result deleteBatch(@RequestBody BatchDeleteCommand batchDeleteCommand){
        vocCategoryService.deleteBookCategories(batchDeleteCommand);
        return Result.ok();
    }

}
